﻿/******************************************************************
** 文 件 名: BD_ProjectCompany_DAL.cs
** Copyright (c) 2010-2012 Honestysoft (GuangZhou) Co.,LTD
** 创 建 人: 此代码由生成器自动生成
** 创建日期: 2012-3-9 18:45:27
** 描    述: 实现公共部分的数据访问封装，提供项目参建单位的数据访问类
** 版    本: 2.0.0.0
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using Honestysoft.BaseObject;
using Honestysoft.Financing.Model;

namespace Honestysoft.Financing.DataAccess
{
	/// <summary>
    /// BD_ProjectCompany数据访问类
    /// </summary>
	public partial class BD_ProjectCompany_DAL : BaseDataAccess<BD_ProjectCompany>
    {		
		/// <summary>
        /// 构造函数，使用指定的连接字符串
        /// </summary>
        /// <param name="connectionStringName">连接字符串名称</param>
        public BD_ProjectCompany_DAL(string connectionStringName)
            : base(connectionStringName)
        {

        }

        /// <summary>
        /// 得到项目参建单位
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="projectCategory"></param>
        /// <param name="projectName"></param>
        /// <param name="unitType"></param>
        /// <param name="compName"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="pageCount"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetProjectCompany(string projectId, string projectCategory, string projectName, EnumItem.UnitType? unitType, string compName, int pageSize, int currentPageIndex, out int pageCount, out int recordCount)
        {
            DbParameter pProjectID = CreateParameter("ProjectID");
            pProjectID.DbType = DbType.String;
            pProjectID.Value = projectId;
            DbParameter pProjectCategory = CreateParameter("ProjectCategory");
            pProjectCategory.DbType = DbType.String;
            pProjectCategory.Value = projectCategory;
            DbParameter pProjectName=CreateParameter("Name");
            pProjectName.DbType= DbType.String;
            pProjectName.Value=projectName;
            DbParameter pUnitType = CreateParameter("UnitType");
            pUnitType.DbType = DbType.String;
            pUnitType.Value = unitType.HasValue ? ((int)unitType.Value).ToString() : "";
            DbParameter pCompName=CreateParameter("CompName");
            pCompName.DbType = DbType.String;
            pCompName.Value = compName;
            string sql = string.Format(@"Select A.*,B.SN+' '+B.Name ProjectName,B.SortCode ProjectSort,C.CompName
                    From BD_ProjectCompany A
                    Inner Join BD_Project B On A.ProjectID = B.ID
                    Inner Join Org_Company C ON A.CompanyID=C.ID Where 1=1 {0} {1} {2} {3} {4}",
                                                                   string.IsNullOrEmpty(projectName) ? "" : string.Format(" And B.Name Like '%'+{0}+'%' ", pProjectName.ParameterName),
                                                                   unitType.HasValue ? string.Format(" And A.UnitType={0} ", pUnitType.ParameterName) : "",
                                                                   string.IsNullOrEmpty(compName) ? "" : string.Format(" And C.CompName Like '%'+{0}+'%' ", pCompName.ParameterName),
                                                                   string.IsNullOrEmpty(projectId) ? "" : string.Format(" And A.ProjectID={0}",pProjectID.ParameterName),
                                                                   string.IsNullOrEmpty(projectCategory) ? "" : string.Format(" And B.ProjectCategory={0}", pProjectCategory.ParameterName));
            DbCommand command = GetDbCommand(sql);
            if (!string.IsNullOrEmpty(projectName)) { command.Parameters.Add(pProjectName); }
            if (unitType.HasValue) { command.Parameters.Add(pUnitType); }
            if (!string.IsNullOrEmpty(compName)) { command.Parameters.Add(pCompName); }
            if (!string.IsNullOrEmpty(projectId)) { command.Parameters.Add(pProjectID); }
            if (!string.IsNullOrEmpty(projectCategory)) { command.Parameters.Add(pProjectCategory); }
            return ExecuteDataTable(command, "ProjectSort,UnitType", pageSize, currentPageIndex, out pageCount, out recordCount);
        }
    }
}
